package com.hzit.deadqueue.controller;

import com.hzit.deadqueue.config.MqConfig;
import com.hzit.deadqueue.customer.MyMessagePostProcessor;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    private AmqpTemplate amqpTemplate;

    @Autowired
    private RabbitTemplate rabbitTemplate;

    /**
     *
     * @param type
     * @return
     */
    @RequestMapping("/dQUEUE")
    public String testDeadQueue(@RequestParam("type") String type) {

        // 设置这条消息的过期时间
        rabbitTemplate.convertAndSend(MqConfig.BUSINESS_EXCHANGE_NAME, "", type, message -> {
            MessageProperties messageProperties = message.getMessageProperties();

            messageProperties.setExpiration("3000");
            return message;
        });

        return "success";
    }
}
